import socket
import threading
from concurrent.futures import ThreadPoolExecutor

# 创建套接字
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 连接服务器
host = '114.215.65.250'
port = 4509
sock.connect((host, port))

# 发送登录命令
username = 'farsight8'
password = '123456'
login_cmd = f'KEY:{username}+{password}'
sock.sendall(login_cmd.encode())

# 等待接收响应
repsond = sock.recv(1024).decode()
print(repsond)

if 'login-success' in repsond:
    print('登录成功')
    # 控制设备
    while True:
        device_name = input('请输入设备名称：')
        sub_device_name = input('请输入子设备名称：')
        do_cmd = input('请输入命令：')
        cmd = f'ORDER:{device_name}+{sub_device_name}={do_cmd}'
        print(cmd)
        sock.sendall(cmd.encode())
else:
    print('登录失败')

# 关闭套接字
sock.close()

